<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" session="false" %>
<%@ page import="com.atozsoft.commonutil.Constants"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="com.eos.data.datacontext.UserObject" %>
<%@ page import="commonj.sdo.DataObject"%>
<%@ page import="org.gocom.components.coframe.rights.dataset.CapUser"%>
<%@ page import="java.math.BigDecimal"%>	
<%@ page import="com.eos.engine.component.ILogicComponent"%>
<%@ page import="com.primeton.ext.engine.component.LogicComponentFactory"%>
	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<%@include file="/common.jsp"%>
	<%@include file="/common/common.jsp"%>
    <%@include file="/coframe/tools/skins/common.jsp"%>
	<title>项目阶段性工作汇报管理详细</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <%
        // 来源操作flg
		String actionFlg = "";
		if(request.getParameter("actionFlg")!=null){
			actionFlg = (String)request.getParameter("actionFlg");
		}
		// 阶段性汇报ID
		String stageid = "";
		if(request.getParameter("stageId")!=null){
			stageid = (String)request.getParameter("stageId");
		}
    	// 项目ID
		String projectid = "";
		if(request.getParameter("projectId")!=null){
			projectid = (String)request.getParameter("projectId");
		}
    	//===== BEG 添加流程实例ID为传入参数，用于查询实体数据  add 2014-12-09 houfy
    	//流程实例ID
 	 	String processInstId = "";
		if(request.getParameter("processInstId")!=null){
			processInstId = (String)request.getParameter("processInstId");
		}
		
		//流程实例工作项ID
 	 	String workitemid = "";
		if(request.getParameter("workitemid")!=null){
			workitemid = (String)request.getParameter("workitemid");
		}
		//节点名称
		String activitydefid = "";
		if(request.getParameter("activitydefid")!=null) {
			activitydefid = (String)request.getParameter("activitydefid");
		}else{
			activitydefid = "null";
		}
		//打开方式
		String webType = "";
		if(request.getParameter("webType")!=null) {
			webType = (String)request.getParameter("webType");
		}
 	 	//===== END 添加流程实例ID为传入参数，用于查询实体数据  add 2014-12-09 houfy
	%>
</head>
<body>
	<div id="showbtnArea" class="nui-toolbar" style="padding:0px;" borderStyle="border:0;">
			<table width="100%">
		    	<tr>
		        	<td style="text-align:right;">
		          		<a id="okBtn" class="nui-button" iconCls="icon-save" onclick="onOk">保存</a>
		          		<span style="display:inline-block;width:5px;"></span>
		       		    <a id="submitBtn" class="nui-button" style="width:60px;" iconCls="icon-upload" onclick="submit()">提交</a>
		        	</td>
		      	</tr>
		    </table>
		</div>
	<div id="editstageForm" style="padding-top:10px;">
		<!-- 阶段性汇报ID -->
  		<input id="stagereportid" class="nui-hidden" name="stage.stagereportid"/>
		<input id="status" class="nui-hidden" name="stage.status"/>
    	<table style="width:100%;height:100%;table-layout:fixed;" class="nui-form-table">
      		<tr>
      			<th class="nui-form-label"><font color="red">*</font>&nbsp;工作汇报名称：</th>
        		<td>
          			<input id="theme" class="nui-textbox nui-form-input" name="stage.theme" required="true" requiredErrorText="工作汇报名称不能为空！"/>
        		</td>
        		<th class="nui-form-label"><font color="red">*</font>&nbsp;项目名称：</th>
        		<td>
          			<input id="projectid" class="nui-buttonedit nui-form-input" style="width:100%;" name="stage.projectid"  required="true" requiredErrorText="项目名称不能为空！" allowInput="false" onbuttonclick="userData"/>
        		</td>
      		</tr>
      		<tr class="odd">
      			<th class="nui-form-label">项目编号：</th>
        		<td>
          			<input id="projectfilecode" class="nui-textbox nui-form-input" name="stage.projectfilecode"/>
        		</td>
      			<th class="nui-form-label">项目执行期限：</th>
		        <td nowrap="nowrap">
	                <input id="startdate" class="nui-datepicker"  name="stage.startdate" style="width:48.5%;"/>
							-
					<input id="enddate" class="nui-datepicker"  name="stage.enddate" style="width:48.5%;"/>
		        </td>
      		</tr>	
      		<tr>
      			<th class="nui-form-label"  nowrap="nowrap">项目经费（万元）：</th>
        		<td>
          			 <input id="bidamount" class="nui-textbox nui-form-input"  style="width:100%;text-align:right;" inputStyle="text-align:right;" name="stage.bidamount"/>
        		</td>
        		<th class="nui-form-label">项目实施单位：</th>
        		<td>
          			<input id="bidwinner" class="nui-textbox nui-form-input" style="width:100%;" name="stage.bidwinner"/>
        		</td>
      		</tr>
      		<tr class="odd">
        		<th class="nui-form-label"  nowrap="nowrap">项目主管：</th>
        		<td>
          			 <input id="projectleader" class="nui-buttonedit nui-form-input" style="width:100%;" name="stage.projectleader"  allowInput="false" />
        		</td>
        		<th class="nui-form-label">业务主管部门：</th>
        		<td>
          			<input  id="departmentid" class="nui-treeselect nui-form-input" name="stage.departmentid" 
			       			url="com.shendong.mis.common.queryOrgOrganization.biz.ext" multiSelect="false"  valueFromSelect="false"
        					dataField="datas" textField="orgname" valueField="orgid" parentField="parentorgid"   allowInput="false"
       						showRadioButton="true" showFolderCheckBox="false"/>
        		</td>
        	</tr>		
        	<tr>
        		<th class="nui-form-label"  nowrap="nowrap"><font color="red">*</font>&nbsp;项目执行单位：</th>
        		<td>
          			 <input id="projectimplementationunit" class="nui-textbox nui-form-input" style="width:100%;" name="stage.projectimplementationunit" required="true" requiredErrorText="项目执行单位不能为空！"/>
        		</td>
        		<th class="nui-form-label"><font color="red">*</font>&nbsp;项目执行情况：</th>
        		<td>
          			<input id="projectimplementationtype" class="nui-dictcombobox nui-form-input"  name="stage.projectimplementationtype" allowInput="false" dictTypeId="MIS_PROJECTIMPLEMENTATIONTYPE" required="true" requiredErrorText="项目执行情况不能为空！"/>
        		</td>
        	</tr>	
        	<tr class="odd">
        		<th class="nui-form-label"  nowrap="nowrap">阶段类型：</th>
        		<td>
          			 <input id="stagetype" class="nui-dictcombobox nui-form-input" style="width:100%;" name="stage.stagetype"  showNullItem="true" allowInput="false" dictTypeId="MIS_STAGETYPE"/>
        		</td>
        		<th class="nui-form-label">阶段子类型：</th>
        		<td>
          			<input id="stagemark" class="nui-dictcombobox nui-form-input"  name="stage.stagemark"  showNullItem="true" allowInput="false" dictTypeId="MIS_STAGEMARK"/>
        		</td>
        	</tr>	
      		<tr>
        		<th class="nui-form-label"  nowrap="nowrap">项目完成度（%）：</th>
        		<td>
          			 <input id="completionpercentage" class="nui-textbox nui-form-input" style="width:100%;text-align:right;" name="stage.completionpercentage" required="true" requiredErrorText="项目完成度（%）不能为空！"/>
          		</td>
        		<th class="nui-form-label">汇报年度：</th>
        		<td>
        			<input id="reportyear" class="nui-textbox nui-form-input" style="width:100%;" name="stage.reportyear"  required="true" requiredErrorText="汇报年度不能为空！"/>
        		</td>
        	</tr>
        	<tr class="odd">
        		<th class="nui-form-label">简要说明：</th>
        		<td  colspan="3">
          			<input id="note" class="nui-textarea nui-form-input" name="stage.note" vtype="rangeChar:0,1300" rangeCharErrorText="简要说明长度不能超过1300！"/>
        		</td>
      		</tr>
      		<tr>
        		<th class="nui-form-label">备注：</th>
        		<td  colspan="3">
          			<input id="remark" class="nui-textarea nui-form-input" name="stage.remark" vtype="rangeChar:0,1300" rangeCharErrorText="备注长度不能超过1300！"/>
          			<!-- 附件 -->
          			<input id="attachment" class="nui-hidden" name="stage.attachment"/>
        		</td>
      		</tr>
    	</table>
	<!-- 	<div style="width:100%;padding:2px 0px 0px 0px;">
			<div class="nui-toolbar" style="border-bottom:0;">
	        	<table style="width:100%;">
	            	<tr>
			            <td style="width:50%;">
			                <a class="nui-button" id="uploadify">上传</a>
			            	<a id="deleteFile" class="nui-button" onclick="removeFile()" style="margin-left: 85px; width:60px;">删除</a>
			            </td>
				    	<th align="left">附件</th>
		            </tr>
		        </table>
	    	</div>
	    </div>
    	<div class="nui-fit" style="width:100%;min-height: 83px;height: 85px;">
  			<div id="attachmentDatagrid" class="nui-datagrid" style="width:100%;height:100%" sizeList="[5,10,20,50]"  
  				idField="fileid" dataField="cmFiles" url="com.austar.cm.common.queryUplodeFileListByIds.biz.ext" 
		    	allowResize="false" showPager="false" showReloadButton="false" totalField="total" multiSelect="true">
		    	<div property="columns">
		        	<div field="fileid" visible="false">ID</div>
		        	<div field="filepath" visible="false">路径</div>
          			<div name="checkcolumn" type="checkcolumn" headerAlign="center" width="10px" align="center"></div>
		        	<div type="indexcolumn" headerAlign="center" width="20px" align="center">序号</div>
		        	<div field="uploadname" headerAlign="center" allowSort="true" renderer="renderOnfileName">文件名称</div>
		    	</div>
			</div>
	    </div> -->
	</div>
	<script type="text/javascript">
    	nui.parse();
    	
    	//项目相关字段不可编辑
    	nui.get("startdate").disable();
    	nui.get("enddate").disable();
    	nui.get("projectfilecode").disable();
    	nui.get("bidamount").disable();
    	nui.get("bidwinner").disable();
    	nui.get("projectleader").disable();
    	nui.get("departmentid").disable();
    	
    	var form = new nui.Form("#editstageForm");
    	var grid = nui.get("attachmentDatagrid");
    	var actionFlg="<%=actionFlg%>";
    	var stageid="<%=stageid%>";
    	var projectid="<%=projectid%>";
    	var uploadFlg = true;
    	var processInstId = "<%=processInstId %>" ;
    	var workitemid ="<%=workitemid%>";
	    var activitydefid = "<%=activitydefid %>";
 		var webType = "<%=webType %>";
    	 
    	if(actionFlg=="add"|| actionFlg=="processStart")
    	{	    
    		 //setViewClass(actionFlg);
    	}else if(actionFlg=="process"){
    		//从流程业务关系表中查询关系数据
    		if (processInstId!=null && processInstId!= ""){
    			var processJson =  nui.encode({processInstId:processInstId});
    			//nui.alert(nui.encode(processJson));
    			$.ajax({
			        url:"com.atozsoft.wf.processOperate.queryProcessBusinessRelationByID.biz.ext",
			        type:'POST',
			        data:processJson,
			        cache:false,
			        async:false,// 禁止异步加载
			        contentType:'text/json',
			        success:function(text){
			        	stageid = text.pBusiness.keyvalue;
			        },
	                error: function () {
	                	nui.alert("数据异常！", "提示");
	                }
		      	});
    		}
	
    		var stageJson = nui.encode({stagereportid:stageid,projectid:projectid});
		       //各种监听事件
			   $.ajax({
				     url:"com.shendong.mis.projectStageReport.queryProjectStageByID.biz.ext",
				     type:'POST',
				     data:stageJson,
			         contentType:'text/json',
			 	     async:false,
			 	     cache:false,
			 	     success:function(text){
			 	       form.setData(text);
	                   form.setChanged(false);
	                    nui.get("projectid").setValue(text.stage.projectid);
                        nui.get("projectid").setText(text.stage.projectname);   
                        nui.get("projectleader").setValue(text.stage.projectleader);
                        nui.get("projectleader").setText(text.stage.projectleadername); 
                        nui.get("departmentid").setValue(text.stage.departmentid); 
                        nui.get("departmentid").setText(text.stage.departmentname);   
                        nui.get("projectfilecode").setValue(text.stage.projectfilecode);
                       	nui.get("startdate").setValue(text.stage.startdate);
                        nui.get("startdate").setText(text.stage.startdate);
                        nui.get("enddate").setValue(text.stage.enddate);
                        nui.get("enddate").setText(text.stage.enddate);
                        nui.get("bidamount").setValue(text.stage.bidamount);
                        nui.get("bidwinner").setValue(text.stage.bidwinner);
			 	     }
			  });	
    	}else{
    		var json = nui.encode({stagereportid:stageid,projectid:projectid});
		     //各种监听事件
			   $.ajax({
				     url:"com.shendong.mis.projectStageReport.queryProjectStageByID.biz.ext",
				     type:'POST',
				     data:json,
			         contentType:'text/json',
			 	     async:false,
			 	     cache:false,
			 	     success:function(text){
			 	       form.setData(text);
	                   form.setChanged(false);
	                    nui.get("projectid").setValue(text.stage.projectid);
                        nui.get("projectid").setText(text.stage.projectname);  
                        nui.get("projectleader").setValue(text.stage.projectleader);
                        nui.get("projectleader").setText(text.stage.projectleadername); 
                        nui.get("departmentid").setValue(text.stage.departmentid); 
                        nui.get("departmentid").setText(text.stage.departmentname);   
                        nui.get("projectfilecode").setValue(text.stage.projectfilecode);
                       	nui.get("startdate").setValue(text.stage.startdate);
                        nui.get("startdate").setText(text.stage.startdate);
                        nui.get("enddate").setValue(text.stage.enddate);
                        nui.get("enddate").setText(text.stage.enddate);
                        nui.get("bidamount").setValue(text.stage.bidamount);
                        nui.get("bidwinner").setValue(text.stage.bidwinner);
			 	     }
			  });	
    	}
    	
		setViewClass(actionFlg);
	    
	     // 设置编辑样式
		function setViewClass(flg){
			if(flg=="add" || flg =="processStart"){
				nui.get("submitBtn").disable();
			}else if(flg=="update"){
				nui.get("submitBtn").enable();
			}else if(flg=="view"){
				nui.get("theme").disable();
				nui.get("projectid").disable();
				nui.get("projectfilecode").disable();
				nui.get("startdate").disable();
				nui.get("enddate").disable();
				nui.get("bidamount").disable();
				nui.get("bidwinner").disable();
				nui.get("projectleader").disable();
				nui.get("departmentid").disable();
				nui.get("projectimplementationunit").disable();
				nui.get("projectimplementationtype").disable();
				nui.get("stagetype").disable();
				nui.get("stagemark").disable();
				nui.get("completionpercentage").disable();
				nui.get("reportyear").disable();
				nui.get("note").disable();
				nui.get("remark").disable();
				nui.get("okBtn").disable();
				var status = nui.get("status").getValue();
				if(status=="0"){
					nui.get("submitBtn").enable();
				}else{
					nui.get("submitBtn").disable();
				}
			}else{
				//按钮隐藏
				$("#showbtnArea").hide();
				
				nui.get("theme").disable();
				nui.get("projectid").disable();
				nui.get("projectfilecode").disable();
				nui.get("startdate").disable();
				nui.get("enddate").disable();
				nui.get("bidamount").disable();
				nui.get("bidwinner").disable();
				nui.get("projectleader").disable();
				nui.get("departmentid").disable();
				nui.get("projectimplementationunit").disable();
				nui.get("projectimplementationtype").disable();
				nui.get("stagetype").disable();
				nui.get("stagemark").disable();
				nui.get("completionpercentage").disable();
				nui.get("reportyear").disable();
				nui.get("note").disable();
				nui.get("remark").disable();
				nui.get("okBtn").disable();
				nui.get("submitBtn").disable();
			}
	      
	    }
    	
    	//PROCESS BEG ============== 流程操作代码 ==============
		
    	// 设置不可编辑样式
        function noEdit(){
		    setViewClass();
        }
	    
		// 提交
	    function submit(){
			var checker = "";
	        
	        nui.open({
	            url: "<%=request.getContextPath()%>/mis/orgUser/selectEmployee.jsp?processInstId=" + processInstId+ "&workitemid="+workitemid+"&empid=N&role=6",
		        title: "审批者选择",
				width: 870,
                height: 550,
                onload: function () {
                	var iframe = this.getIFrameEl();
			        iframe.contentWindow.SetData({multiSelect:'false'});
                },
                ondestroy: function (action) {
              	 	if(action=="ok"){
              	 		var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = nui.clone(data);    //必须克隆返回值
                        // 审批人选定赋值
                        checker = data.empid;  
                        submitData(checker); 	
                    }
                }
		    });
		}
		
		// 提交
	    function submitData(checker){
	        var form = new nui.Form("#editstageForm");
	        form.setChanged(false);
	        //流程发起
	        var urlStr = "com.shendong.mis.projectStageReport.submitStagereport.biz.ext";
	        form.validate();
	        if(form.isValid()==false) return;
	        var data = form.getData(false,true);
	        if(checker == "" || checker == null) return;
	        var json = nui.encode({stage:data.stage,checker:checker});
	        $.ajax({
	        	url:urlStr,
	        	type:'POST',
	        	data:json,
	        	cache:false,
	        	contentType:'text/json',
	        	success:function(text){
	            	var returnJson = nui.decode(text);
	            	if(returnJson.resultStr == "success"){
	              		nui.get("stagereportid").setValue(text.stage.stagereportid);
	              		nui.get("status").setValue(text.stage.status);
	              		nui.alert("流程发起成功！");
			            //更新页面状态
			            actionFlg="process";
			            setViewClass(actionFlg);
	              
	           		}else{
	              		nui.alert("流程发起失败", "系统提示", function(action){
			                if(action == "ok" || action == "close"){
			                  //CloseWindow("saveFailed");
			                }
	               		});
	             	}
	           	}
	        });
	    }
	    
	    // 流程执行父页面调用接口
        var checkSet = "";
	    
		 //获取节点选择窗口的筛选值
	    function getCheckSet(){
        	return checkSet;
        }
	    // 流程执行父页面调用接口
        parent["infoFrame"] = window;
         // 父页面调用的字段控制操作
        // 01 显示 工时（workhours）字段
	    //传递控制参数
       var parentWorkType = "2345";
       
       function onParentCallCheck(){
       		var str = "false";
	        return str;
       	}
       
        // 父页面调用的保存操作，同意操作打开之前执行
	    function onParentCallOk(){
	        // 设定保存返回值   
        	var resultStr = "";
	        return resultStr;
	    }
	    
	    // 工作项确认同意后调用的操作
	    function onParentCallAfterOk(){
	    }
	    
	    // 流程与业务参数传递函数
	    function onParentEditParams(){
	    
	    }
	    
	    // 等待提示
		function loading(){
			nui.mask({el: document.body,cls: 'mini-mask-loading',html: '处理中...'});
		}
		
		// 结束等待提示
	    function endLoading(){
	    	nui.unmask(document.body);
    	}
    	
	    // 流程完成后，打开页面查看时调用的操作
	    function onParentCallAfterStop(){
	    	
	    }
	    
	    // 父页面调用的打印操作
	    function onParentCallPrint(){
	    	//parent.printPage();
	    }
	    
	    // 更新流程业务关系表
	    function updatePBRelation(){
	    }

	  	//PROCESS END ============== 流程操作代码 ==============

    	// 保存按钮
	    function onOk(){
	    	saveData();
	    }
	    
        // 保存表单数据
		function saveData() {
			var form = new nui.Form("#editstageForm");
	        form.setChanged(false);
	        //保存
	        var urlStr = "com.shendong.mis.projectStageReport.saveProjectStage.biz.ext";
	        form.validate();
	        if(form.isValid()==false) return;
	
	        var data = form.getData(false,true);
	        var json = nui.encode(data);
			//alert(json);
	        $.ajax({
	          url:urlStr,
	          type:'POST',
	          data:json,
	          cache:false,
	          contentType:'text/json',
	          success:function(text){
	            var returnJson = nui.decode(text);
	            
	            if(returnJson.resultStr == "success"){
	              nui.get("stagereportid").setValue(text.stage.stagereportid);
	              nui.get("status").setValue(text.stage.status);
	              nui.alert("保存成功！");
	              //更新页面状态
	              actionFlg="update";
	              setViewClass(actionFlg);
	              
	            }else{
	              nui.alert("保存失败", "系统提示", function(action){
	                if(action == "ok" || action == "close"){
	                  //CloseWindow("saveFailed");
	                }
	              
	               });
	             }
	           }
	         });
	    }
	  	
		//项目名称的popup 
       function userData(){
	    	nui.open({
                url: "<%=request.getContextPath()%>/mis/common/selectProject_popup.jsp?stepid=2",
                title: "项目名称",
                width: 1000,
                height: 550,
                onload: function () {
                	/* var iframe = this.getIFrameEl();
			        iframe.contentWindow.SetData({stepid:"2"});  */
                },
                ondestroy: function (action) {
              	 	if(action=="ok"){
              	 		var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = nui.clone(data);    //必须克隆返回值
                        //alert(nui.encode(data));
                       
                       
                        // 主管所领导赋值
                        nui.get("projectid").setValue(data.projectid);
                        nui.get("projectid").setText(data.projectname);   
                        
                        nui.get("projectleader").setValue(data.projectleader);
                        nui.get("projectleader").setText(data.empname); 
                        
                        nui.get("departmentid").setValue(data.departmentid); 
                        nui.get("departmentid").setText(data.departmentname);   
                        
                        nui.get("projectfilecode").setValue(data.projectfilecode);
                        
                       	nui.get("startdate").setValue(data.startdate);
                        nui.get("startdate").setText(data.startdate);
                        
                        nui.get("enddate").setValue(data.enddate);
                        nui.get("enddate").setText(data.enddate);
                        
                        nui.get("bidamount").setValue(data.bidamount);
                       
                        
                        nui.get("bidwinner").setValue(data.bidwinner);
                        
                        	 	
                    }
                }
            });
	    }
		
    </script>
</body>
</html>